import grails.util.GrailsUtil

class BootStrap {
  def init = { servletContext ->
       switch(GrailsUtil.environment){
         case "development":
           println "#### Development Mode (Start Up)"
           createData()
           break
         case "test":
           println "#### Test Mode (Start Up)"
           break
         case "production":
           println "#### Production Mode (Start Up)"
           break
       }
   }

   def destroy = {
       switch(GrailsUtil.environment){
         case "development":
           println "#### Development Mode (Shut Down)"
           deleteData()
           break
         case "test":
           println "#### Test Mode (Shut Down)"
           break
         case "production":
           println "#### Production Mode (Shut Down)"
           break
       }
   }
	
	
  def createData = {  
    def hotel = planner.Hotel.findByName("Marriott")    
    if(!hotel){
      new planner.Hotel(name:"Marriott").save()
    }
  
    hotel = planner.Hotel.findByName("Sheraton")
    if(!hotel){
      new planner.Hotel(name:"Sheraton").save()
    }
  }

  def deleteData = {
    def hotel = planner.Hotel.findByName("Marriott")
    if(hotel){ 
      planner.Hotel.findByName("Marriott").delete()
    }
  
    hotel = planner.Hotel.findByName("Sheraton")
    if(hotel){
      planner.Hotel.findByName("Sheraton").delete()
    }
  }    
} 